<div id="main" align='center'>
    <br />
    <?php if(isset($message)) echo "<center><font color=red><b>$message</b></font></center><br />"; ?>
    <table valign="MIDDLE" border='1' bordercolor='#ACACAC' width='600'>
        <thead>
            <tr>
                <th width='50'>Mã lớp</th>
                <th width='50'>Mã môn</th>
                <th width='220'>Tên môn</th>
                <th width='40'>Học kì</th>
                <th width='200'>ngày thi</th>
                <th width='60'>Thời gian(phút)</th>
                <th width='50'></th>
            </tr>
        </thead>       
        <tbody>
            <?php
            foreach($exams as $exam)
            {
                $tz = new DateTimeZone('Asia/Bangkok');
                $time = new DateTime($exam->time, $tz);
                $tempTime = new DateTime($exam->time, $tz);;
                $now = new DateTime("now", $tz);
                $url = Utility::getSiteUrl();
                $finishTime = new DateTime($exam->finishtime, $tz);
                ?>
                <tr>
                    <td><center><b><?php echo $exam->id; ?></b></center></td>
                    <td><?php echo $exam->subjectid; ?></td>
                    <td><?php echo $exam->subject; ?></td>
                    <td><?php echo $exam->semester; ?></td>
                    <td><?php echo $exam->time; echo ($exam->isreal==1)?'(Thi thật)':'(Thi thử)'; ?></td>
                    <td><?php echo $exam->totaltime; ?></td>
                    <td><?php if ($now>$tempTime && $now < $tempTime->add(new DateInterval('PT20M')) &&
                                        $exam->finishtime==null)
                                echo "<a href='$url"."/testing/start/"."$exam->id/$exam->subjectid/$exam->totaltime'>Bắt đầu</a>";
                            else if ($now>$time && $now < $finishTime && $exam->finishtime!=null)
                                echo "<a href='$url"."/testing/start/"."$exam->id/$exam->subjectid/$exam->totaltime'>Tiếp tục</a>";
                    ?></td>
                </tr>
                <?php
            }
            ?>
        </tbody>
    </table>
</div>
